using System;

namespace codebase.UI
{
    public abstract class Control
    {
        public int Left;
        public int Top;
        public int Width;
        public int Height;

        public Window Parent;

        public int BackgroundColor = ColorExtensions.WHITE16;
        public bool Visible = true;

        protected virtual void Draw()
        {
            throw new Exception("Draw() not implemented");
        }

        protected virtual void DrawAll()
        {
            throw new Exception("DrawAll() not implemented");
        }

#if !PC
        public virtual void touchDown(object o, TouchEventArgs e)
        {
        }

        public virtual void touchMove(object o, TouchEventArgs e)
        {
        }

        public virtual void touchUp(object o, TouchEventArgs e)
        {
        }
#endif

        public virtual void Redraw()
        {
            if(Visible) DrawAll();
        }

        public virtual void Refresh()
        {
            if (Visible) Draw();
        }

        protected virtual Boolean IsPointInControl(int x, int y)
        {
            if (Visible)
            {
                if ((x >= (Left + Parent.Left)) && (x <= (Left + Parent.Left + Width) - 1) &&
                (y >= (Top + Parent.Top)) && (y <= (Top + Parent.Top + Height) - 1))
                {
                    return true;
                }
            }
            return false;
        }

        protected virtual Boolean IsPointInControlOffset(int x, int y,int ox, int oy)
        {
            if (Visible)
            {
                if ((x >= Left + Parent.Left) && (x <= Left + Parent.Left + Width + ox) &&
                (y >= Top + Parent.Top) && (y <= Top + Parent.Top + Height + oy))
                {
                    return true;
                }
            }
            return false;
        }
    }
}
